// 验证规则
$('#tobuy').validate({
    rules: {
        buy_num: {
            required: true,
            digits: true,
            min: 1,
            buy:true
        },
        password: {
            required: true,
            password: true
        }
    },
    messages: {},
    errorPlacement: function (error, element) {
        $(element).siblings('.u-ts').html(error)
    },
    errorElement: 'span',
    submitHandler: function (form) {
        $(form).ajaxSubmit({
            dataType: "json",
            type: "post",
            success: function (data) {
                console.log(data);
                if (data.code === 0) {
                    alert(data.msg)
                }
            }
        })
    }
});

jQuery.validator.addMethod('password', function (value, element) {
    var password = /^[a-z0-9_-]{6,18}$/.test(value);
    return this.optional(element) || password
}, '请输入6-18位字母，数字_-');

jQuery.validator.addMethod('buy', function (value, element) {
    var password = parseFloat($('#dzg_wallet_balance').val()) - value * $('#buy_num').val();
    return this.optional(element) || (password >= 0)
}, '您的余额已不足，请充值');

